# 变量作用域
# 函数里面的 x,y 和函数外面的 x,y 不是同一组变量
# def getPoint():
#     # 出了作用域就失效
#     x =10
#     y = 20
#     return x,y
#
# x,y = getPoint()
# print(x,y)

# 全局变量
# x = 10
# def func():
#     # 局部变量
#     x = 20
#     print(f'函数内部：x = {x}')
#
# func()
# print(f'函数外部：x = {x}')


# x = 10
# def func():
#     print(f'x = {x}')
#
# func()


# 使用这个函数，把全局变量 x 给改成 20！
# x = 10
# def func():
#     # global 声明这个变量是全局变量
#     global x
#     x = 20
#
# func()
# print(f'x = {x}')


# # 调试观察程序执行
# def func():
#     print("执行函数代码")
#     print("执行函数代码")
#     print("执行函数代码")
#
# print('111111')
# func()
# print('222222')
# func()
# print('333333')
# func()
# print('444444')

# 链式调用
# def isOdd(num):
#     if num % 2 == 0:
#         return False
#     return True
#
# def Add(num1, num2):
#     return num1 + num2
#
# print(isOdd(Add(2, 2)))

# # 调试看一下调用过程
# def a():
#     num1 = 10
#     print('函数 a')
#
# def b():
#     num2 = 20
#     a()
#     print('函数 b')
#
# def c():
#     num3 = 30
#     b()
#     print('函数 c')
#
# def d():
#     num4 = 40
#     c()
#     print('函数 d')
#
# d()

# 函数递归
# def factor(n):
#     if n == 1:
#         return 1
#     return n * factor(n-1)
#
# print(factor(5))

# 参数默认值
# def add(x, y, debug=False):
#     if debug:
#         print(f'x = {x}, y = {y}')
#     return x + y
#
# result = add(1, 2, True)
# print(result)

# def test(x, y):
#     print(f'x = {x}')
#     print(f'y = {y}')
#
# test(x = 1, y = 2) # 明确表示要传的参数给谁


# 列表
# a = []
# print(type(a))
#
# b = list()
# print(type(b))
#
# a = [1, 2, 3]
# print(a)

# a = [1, 2, 3]
# print(a[2])
# a[2] = 100
# print(a[2])

# a = [1,2,3,4,5,6,7,8,9]
# # print(len(a))
# print(a[len(a)-1])
# # -1 倒数第一个元素的下标
# print(a[-1])

# # 列表切片的操作
# a = [1,2,3,4,5]
# # 左闭右开[)
# print(a[1:3]) # [2, 3]
# print(a[1:])
# print(a[:2])
# print(a[:-1])
# print(a[:])

# 带有步长的切片操作
a = [1,2,3,4,5,6,7,8,9,10]
# print(a[::1])
# print(a[::2])
# print(a[1:-1:2])

# 负数：从后往前取
# print(a[::-1])
# print(a[::-2])

# # 超过范围不会报错，会尽可能给出
# print(a[:100])

#列表遍历
#列表元素不可修改 --- 修改对原本的列表元素无影响
# a = [1,2,3,4,5,6,7,8,9,10]
# for elem in a:
#     elem *= 2
#     # print(elem)
# print(a)

# #列表元素可修改 --- 修改对原本的列表元素有影响
# a = [1,2,3,4,5,6,7,8,9,10]
# for i in range(0,len(a)):
#     # print(a[i])
#     a[i] += 10
#     # print(a[i])
# print(a)


# a = [1,2,3,4,5,6,7,8,9,10]
# i = 0
# while i < len(a):
#     # print(a[i])
#     i = i + 1
# print(a)

